package cn.aicnn.chatssespringboot.controller;

import cn.aicnn.chatssespringboot.service.MetricsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/api/metrics")
public class MetricsController {

    @Autowired
    private MetricsService metricsService;

    @PostMapping("/analyze")
    public ResponseEntity<Map<String, Object>> analyzeZip(@RequestParam("file") MultipartFile file) {
        System.out.println("进入源代码分析！");
        try {
            Map<String, Object> result = metricsService.analyzeUploadedZip(file);
            return ResponseEntity.ok(result);
        } catch (Exception e) {
            return ResponseEntity.status(500).body(Map.of("error", e.getMessage()));
        }
    }
}

